<?php
session_start();
require 'connection.php';
require 'util.php';
$pks = $_SESSION['listedResults'];
$id = substr($_POST['id'], -10);
if(isset($id) && $pks[$id] != ""){
	$pk = $pks[$id];
	$action = isset($_POST['action']) ? $_POST['action'] : "";
	//print_r(getListingAndUserInfo($pk)[0]);
	if($action != "")
	{
		switch($action)
		{
			case 'profile':
				showUserInfo(getListingAndUserInfo($pk)[0]);
				break;
			default:
				showListingInfo(getListingAndUserInfo($pk)[0]);
				break;
		}
	}
	else
	{
		showListingInfo(getListingAndUserInfo($pk)[0]);
	}
	//echo print_r(getListingAndUserInfo($pk));
	//showListingInfo(getListingAndUserInfo($pk)[0]);
	//echo "<div><p>ñañañaña</p></div>";
}else{
	echo "Error while retrieving the info.";
}

function getListingAndUserInfo($listingId){
	$ini = parse_ini_file("ini/queries.ini", true);
	$query = $ini['listings']['listingsFromId'];
	$params = array(
		":resultpk"=>$listingId
		);
	//echo $query;
	return getResultArray($query, $GLOBALS['pdo'], $params);
	//return "a";
}


function showListingInfo($listing){
		$html = "<div class=\"MIP\">
				<!--NAV BAR -->
				<div class=\"MIP-nav-bar\">
						<div class=\"MIP-exit-button-container\" id=\"exit-button\">
							<img class=\"center-vertically\" src=\"img/exit-icon.jpg\" />
						</div>
						<div id=\"home-button\">
							<img src=\"img/profile_icon.png\" class=\"MIP-nav-button center-vertically\" />
						</div>
						<div id=\"picture-button\">
							<img class=\"center-vertically\" src=\"img/photos_icon.png\" />
						</div>

						<div id=\"contact-button\">
							<img class=\"center-vertically\" src=\"img/gem_icon.png\" />
						</div>
				</div>

				<!--IMAGE AND LINK CONTAINER -->
				<div class=\"MIP-listing-heading\">
					<!--OVERLAPPING DIV -->
					<div class=\"listing-info-container\">
							<div class=\"rating center-vertically\">
								<span>9.8</span>
							</div>
							<div class=\"heading center-vertically\">
								<div class=\"title\">
									MERCURIE LONDON HOTEL
								</div>
								<div class=\"address\">
										<i class=\"marker-icon\"></i><span>KENINGSTON, LONDON</span>
								</div>
							</div>
					</div>

					<!--MAIN IMAGE -->
					<div class=\"user-info\">
						<div class=\"picture-container center-vertically\">
							<img class=\"center-vertically\" src='".getProfilePicture($listing['user_fk'])."' />
						</div>
						<div class=\"info center-vertically\">
							<div class=\"name\">
								<span>John Doe</span>
							</div>
							<div class=\"city\">
								<span>LONDON</span>
							</div>
							<div class=\"view-profile-link\">
								<a href=\"#\" id=\"view-profile-link\">View Profile</a>
							</div>
						</div>
					</div>
				</div>
				<!--LISTING IMAGE -->
				<div class=\"listing-image\">
					<div class=\"image-container\"></div>
					<div class=\"slider-control\">
						<div class=\"left center-vertically\"></div>
						<div class=\"right center-vertically\"> </div>
					</div>
				</div>
				<!--INFORMATION CONTAINER -->
				<div class=\"info-container\">
					<div class=\"heading\">
						<div class=\"description\">
							<p>CHINESE / ASIAN</p>
							<div>
								<span>\"The Rooftop bar in the centre of London. Enjoy the sun and view...\"</span><span class=\"rating\">9.8</span>
							</div>
						</div>
						<div class=\"reviews\">
							<div class=\"price\"><span>&#163;34</span></div>
							<div class=\"write-reviews\"><a href=\"#\">WRITE REVIEWS</a></div>
						</div>
					</div>
					<div class=\"span-contact-info-container\">
						<div class=\"span-info\">
								<div class=\"title\">
									<span>SNAP INFORMATION</span>
								</div>
								<div class=\"item\">
									<span>LOCATION</span><span>KENINGSTON, LONDON</span>
								</div>
								<div class=\"item\">
									<span>CUSINE</span><span>NONE</span>
								</div>
								<div class=\"item\">
									<span>VENUE</span><span>BAR</span>
								</div>
								<div class=\"item\">
									<span>AMENITIES</span><span class=\"amenity-item wifi\"></span>
								</div>
								<div class=\"item\">
									<span>RESERVATIONS</span><span>5 DAYS NOTICE</span>
								</div>
							</div>

							<div class=\"contact-info\">
								<div class=\"title\">
									<span>CONTACT</span>
								</div>
								<div class=\"item\">
									<span>ADDRESS</span><span>12 Kensington high st LONDON</span>
								</div>
								<div class=\"item\">
									<span>Tel</span><span>202 1224 445</span>
								</div>
								<div class=\"item\">
									<span>Web</span><span>www.barlondon.com</span>
								</div>
								<div class=\"other-listings\">
									<p>OTHER LISTINGS</p>
									<p><span class=\"gray-text\">BAR, </span> <span class=\"blue-text\">MAYFAIR, </span> <span class=\"blue-text\">LONDON</span></p>
								</div>
							</div>
					</div>
				</div>

		</div>";

		$pictures = getListingPictures(null, false, $listing["pk"]);
		$response = array("html"=>$html, "pictures"=>$pictures);
		echo json_encode($response);
}
function showUserInfo($listing){
	$html =	"<div class=\"MIP\">
				<!--NAV BAR -->
				<div class=\"MIP-nav-bar\">
						<div class=\"MIP-exit-button-container\" id=\"exit-button\">
							<img class=\"center-vertically\" src=\"img/exit-icon.jpg\" />
						</div>
						<div id=\"home-button\">
							<img src=\"img/profile_icon.png\" class=\"MIP-nav-button center-vertically\" />
						</div>
						<div id=\"picture-button\">
							<img class=\"center-vertically\" src=\"img/photos_icon.png\" />
						</div>

						<div id=\"contact-button\">
							<img class=\"center-vertically\" src=\"img/gem_icon.png\" />
						</div>
				</div>

				<!--IMAGE AND LINK CONTAINER -->
				<div class=\"MIP-profile-heading\">
					
					<!--MAIN IMAGE -->
					<div class=\"profile-user-info\">
						<div class=\"picture-container center-vertically\">
							<img class=\"center-vertically\" src='".getProfilePicture($listing['user_fk'])."'/>
						</div>
						<div class=\"info center-vertically\">
							<div class=\"name\">
								<span>John Doe</span>
							</div>
							<div class=\"city\">
								<span>LONDON</span>
							</div>
							<div class=\"address\">
								<i class=\"marker-icon\"></i><span>KINGSTON, LONDON</span>
							</div>
						</div>
					</div>

					<!--OVERLAPPING DIV -->
					<div class=\"listing-link center-vertically\">
							<div class=\"listing-icon-container\">
								
							</div>
							<div class=\"text\">
								<span>LISTING</span>
							</div>
					</div>
				</div>
				<!--profile IMAGE -->
				<div class=\"profile-image\">
					<div class=\"image-container\"></div>
					<div class=\"slider-control\">
						<div class=\"left center-vertically\"></div>
						<div class=\"right center-vertically\"> </div>
					</div>
				</div>
				<!--INFORMATION CONTAINER -->
				<div class=\"profile-info-container\">
					<div class=\"heading\">
						<p>ABOUT ME</p>
						<div>
							<div class=\"description\">
								
								<div>
									<span>I'm just a fun loving guy who has passion for travelling and meeting people all over the world, if you want to meet me just Orb me.</span>
								</div>
							</div>
							<div class=\"follow\">
								<div class=\"plus-icon\"><img src=\"img/comment_icon.png\"></div>
								<div class=\"link\"><a href=\"#\">FOLLOW</a></div>
							</div>
						</div>
					</div>
					<div class=\"span-contact-info-container\">
						<div class=\"span-info\">
								<div class=\"title\">
									<span>SNAP INFORMATION</span>
								</div>
								<div class=\"item\">
									<span>LOCATION</span><span>KENINGSTON, LONDON</span>
								</div>
								<div class=\"item\">
									<span>WORK</span><span>BUILDER</span>
								</div>
								<div class=\"item\">
									<span>AGE</span><span>34</span>
								</div>
							</div>

							<div class=\"contact-info\">
								<div class=\"title\">
									<span>&nbsp;</span>
								</div>
								<div class=\"item\">
									<span>SOCIAL MEDIA</span>
									<span>
										<span class=\"social-media-icon skype\"></span>
										<span class=\"social-media-icon skype\"></span>
									</span>
								</div>
								<div class=\"item\">
									<span>TRIBES</span><span>TREKKING, BEACH, CITY</span>
								</div>
								<div class=\"other-profiles\">
							</div>
					</div>
				</div>

				<div class=\"profile-score-card-other-listings\">
					<div class=\"score-card\">
						<div class=\"title\">
							<span>SCORE CARD</span>
						</div>
						<div class=\"cards-container\">
							<div class=\"card\">
								<div class=\"number blue\">
									<span>16</span>
								</div>
								<div class=\"description\">
									<span>REVIEWS</span>
								</div>
							</div>

							<div class=\"card\">
								<div class=\"number red\">
									<span>16</span>
								</div>
								<div class=\"description\">
									<span>HOSTED</span>
								</div>
							</div>

							<div class=\"card\">
								<div class=\"number purple\">
									<span>16</span>
								</div>
								<div class=\"description\">
									<span>GUEST</span>
								</div>
							</div>

							<div class=\"card\">
								<div class=\"number green\">
									<span>16</span>
								</div>
								<div class=\"description\">
									<span>MEET</span>
								</div>
							</div>
						</div>
					</div>

					<div class=\"other-listings\">
					</div>
				</div>

		</div>";
	$pictures = getUserPictures($listing['user_fk']);
	$response = array("html" => $html, "pictures"=>$pictures);
	//print_r($response);
	echo json_encode($response);
}


?>
